<?php
$this->breadcrumbs=array(
	'Questions'=>array('admin'),
	'Manage',
);

$this->menu=array(
	array('label'=>'List Questions', 'url'=>array('index')),
	array('label'=>'Create Questions', 'url'=>array('create')),
);

Yii::app()->clientScript->registerScript('search', "
$('.search-button').click(function(){
	$('.search-form').toggle();
	return false;
});
$('.search-form form').submit(function(){
	$.fn.yiiGridView.update('questions-grid', {
		data: $(this).serialize()
	});
	return false;
});
");
?>
<?php 

if(!empty($_GET['id']))
{
$quiz=$_GET['id'];
$name=Quiz::model()->find('id=?',array($quiz));
?>
<h1><?php if($name)echo "Manage Questions of Test "."".$name->title;?></h1>

<?php }
else {?>
<h1>Manage Questions</h1><?php }?>
<?php if(Yii::app()->user->hasFlash('success')):?>
   <div class="flash-success" style="color:white;background-color:#669966;">
   <?php echo Yii::app()->user->getFlash('success'); ?>
</div>
<?php endif; ?>



<div class="search-form">
<?php $this->renderPartial('_search',array(
	'model'=>$model,'id'=>$id,
)); ?>
</div><!-- search-form -->

<?php 

if(!empty($_GET['id']))
{ ?>
<div class="row buttons">
<a href="<?php echo Yii::app()->createUrl('/admin/questions/create/id/'.$id);?>" class="button_design">ADD QUESTION</a>
</div>
<?php }
else { ?>
<div class="row buttons">
<a href="<?php echo Yii::app()->createUrl('/admin/questions/create');?>" class="button_design">ADD QUESTION</a>
</div>
<?php }?>

<?php $this->widget('zii.widgets.grid.CGridView', array(
	'id'=>'questions-grid',
	'dataProvider'=>$model->search($id),
	'htmlOptions'=>array('style'=>'cursor: pointer;'),
	'selectionChanged'=>"function(id){window.location='" . Yii::app()->urlManager->createUrl('admin/questions/update', array('id'=>'')) . "/' + $.fn.yiiGridView.getSelection(id);}",
	
	'columns'=>array(
		'id',
		array('name'=>'quiz_id','value'=>'Quiz::model()->findByPk($data->quiz_id)->title'),
		'title',
		'status',
		'level',
		'type',
		
		array(
			'class'=>'CButtonColumn',
		'template' => '{update} {remove}',
			'buttons'=>array(                         
                        'remove' => array(
                                'label'=>'Delete', // text label of the button
                                'url'=>"CHtml::normalizeUrl(array('/admin/Questions/delete', 'id'=>\$data->id))",
                               'imageUrl'=>"/clients/quize/images/delete.png",  // image URL of the button. If not set or false, a text link is used
                                'options' => array('class'=>'show', 'confirm'=>"Are you sure?"), // HTML options for the button
                        ),     
                      ),
		),
	),
)); ?>
